﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using DotNet.Business;
using DotNet.Model;
using DotNet.Common;
using System.Text;
using System.Collections.Generic;

public partial class Admin_AddNews : basePage
{
    NewsBll newsBLL = new NewsBll();
    News news = new News();
    newClassBll nCBll = new newClassBll();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if(Request.QueryString["state"]!=null)
            {
                string state = Request.QueryString["state"].ToString();
                switch (state.Trim())
                {
                    case "insert":
                        Insert();
                        break;
                    default:
                        break;
                }
            }                   
        }
    }
    #region 添加新闻---郑同飞
    /// <summary>
    /// 添加新闻---郑同飞
    /// </summary>
    public void Insert()
    {
        if (Request.Form["title_color"].ToString() == "" || Request.Form["title_color"].ToString() == null)
        {
            news.newName = Request.Form["newName"].ToString();
        }
        else 
        {
            news.newName = "<font color='" + Request.Form["title_color"].ToString() + "'>" + Request.Form["newName"].ToString() + "</font>"; 
        
        }
        news.newClassId = Convert.ToInt32(Request.Form["selectDp"].ToString());
        news.newInfo=Server.HtmlDecode(Request.Form["FCKeditor1"].ToString());
        news.newSDate = DateTime.Now;
        news.newEDate = DateTime.Now;
        news.nTitle =Request.Form["nTitle"].ToString();
        news.nKey=Request.Form["nKey"].ToString();
        news.nDescription=Request.Form["nDescription"].ToString();
        news.nButtom=Request.Form["nButtom"].ToString();
        if (newsBLL.Insert(news))
	    {
             Response.Write("1");
    		 Response.End();
	    }
    }
    #endregion

    #region 自定义下拉框---郑同飞
    /// <summary>
    /// 自定义下拉框---郑同飞
    /// </summary>
    /// <param name="name">空间的id</param>
    /// <returns></returns>
    public string NewsClassDp(string name)
    {
        StringBuilder str = new StringBuilder();
        IList<newClass> list = nCBll.GetModel();
        str.Append("<select name='selectDp' id='" + name + "' style='width:100px;'>");
        str.Append("<option value='0' selected='true'>请选择类别</option>");
        foreach (newClass nc in list)
        {
            str.Append("<option value='" + nc.newClassId + "'>" + nc.newClassName + "</option>");
            
        }     
        str.Append("</select>");
        return str.ToString();
    }
   
    #endregion
}


